package com.ljt.base.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.ViewModel

/**
 * @auther :lujiantao
 * @date :2024/4/23 6:03 PM
 * @desc :activity基类
 */
public abstract class BaseActivity<B : ViewDataBinding,VM:ViewModel> : AppCompatActivity() {

    protected lateinit var binding: B
    protected lateinit var viewModel:VM

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //根据getLayoutResId设置ViewDataBinding实例
        binding = DataBindingUtil.setContentView(this,getLayoutResId())

        //根据
        viewModel = createViewModel()

        //初始化view
        initView()

        //初始化data
        initData()
    }

    /**
     * 返回该activity的xml
     */
    abstract fun getLayoutResId(): Int

    /**
     * 返回viewModel
     */
    abstract fun createViewModel(): VM

    /**
     * 初始化view
     */
    abstract fun initView()

    /**
     * 初始化data
     */
    abstract fun initData()

}